package com.movie.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.movie.api.mapper.FilmVipMapper;
import com.movie.api.model.entity.FilmVip;
import com.movie.api.service.FilmIsVipService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class FilmIsVipServiceImpl extends ServiceImpl<FilmVipMapper, FilmVip> implements FilmIsVipService {
    @Resource
    private FilmVipMapper filmVipMapper;
    @Override
    public boolean isVip(Integer filmId) {
        QueryWrapper<FilmVip> filmVipQueryWrapper = new QueryWrapper<FilmVip>();
        filmVipQueryWrapper.eq("film_id",filmId);
        FilmVip filmVip = filmVipMapper.selectOne(filmVipQueryWrapper);
        return filmVip.getIsVip() != null && filmVip.getIsVip() != 0;
    }

    @Override
    public boolean isVip(String filmId) {
        int filmIdInt = Integer.parseInt(filmId, 10);
        QueryWrapper<FilmVip> filmVipQueryWrapper = new QueryWrapper<FilmVip>();
        filmVipQueryWrapper.eq("film_id",filmIdInt);
        FilmVip filmVip = filmVipMapper.selectOne(filmVipQueryWrapper);
        boolean result = filmVip.getIsVip() != null && filmVip.getIsVip() != 0;
        log.info( "VIP电影：{}",result);
        return result;
    }
}
